package ru.paswd.demo.android.view.ui.activities

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.hilt.android.AndroidEntryPoint
import moxy.MvpAppCompatActivity
import moxy.presenter.InjectPresenter
import moxy.presenter.ProvidePresenter
import ru.paswd.demo.android.view.R
import ru.paswd.demo.android.view.components.HistoryStorage
import ru.paswd.demo.android.view.models.DecisionItem
import ru.paswd.demo.android.view.presenters.HistoryPresenter
import ru.paswd.demo.android.view.ui.adapters.HistoryItemAdapter
import ru.paswd.demo.android.view.ui.views.HistoryView
import javax.inject.Inject

@AndroidEntryPoint
class HistoryActivity : MvpAppCompatActivity(R.layout.activity_history), HistoryView {

    @InjectPresenter
    lateinit var presenter: HistoryPresenter

    @Inject
    lateinit var historyStorage: HistoryStorage

    @ProvidePresenter
    fun providePresenter() =
        HistoryPresenter(
            historyStorage = historyStorage,
        )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val historyList = findViewById<RecyclerView>(R.id.historyList)
        historyList.layoutManager = LinearLayoutManager(this)
        presenter.onInit()
    }

    override fun showHistory(items: List<DecisionItem>) {
        val adapter = HistoryItemAdapter(items)
        val historyList = findViewById<RecyclerView>(R.id.historyList)
        historyList.adapter = adapter
    }
}